import { BasicColumn, FormSchema } from '@/components/Table';
import { h,ref } from 'vue';
import { Select,Input,DatePicker } from 'ant-design-vue';
import Ainput from "@/views/bookManage/components/account/Ainput.vue";
import { useMessage } from '@/hooks/web/useMessage';
import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();

type CheckedType = boolean | string | number;


const names=ref("");
const names2=ref("");

//表格列名
export const columns: BasicColumn[] = [
  {
    title: '群名称',
    dataIndex: 'name',
  },
  {
    title: '部门',
    dataIndex: 'deptNames',
    width: 180,
  },
  {
    title: '统计开始日期',
    dataIndex: 'startDate',
    width: 180,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },

];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '群名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '群名称',
    required: true,
    component: 'Input',
  },
  {
    label: '群主',
    field: 'owner',
    component: 'Input',
    rules: [{ required: true }],
    render: ({ model, field }) => {

      return h(Ainput, {
        placeholder: '请选择人员',
        // value: model[field],
        value: model.owner_name,
        isAdd:false,
        disabled:false,
        mode:"single",// multiple 多选 single 单选
        onChange: (e: ChangeEvent) => {
          model[field] = e.ids;
          model.owner_name=e.names;
        },
      });
    },
  },
  {
    label: '群主-名称',
    field: 'owner_name',
  },
  {
    label: '建群成员-名称',
    field: 'useridlist_name',
  },
  {
    label: '建群成员',
    field: 'useridlist',
    component: 'Input',
    rules: [{ required: true }],
    render: ({ model, field }) => {

      if(!userStore.chatIsUpdate){
        names2.value="";
      }
      return h(Ainput, {
        placeholder: '请选择人员',
        value: model.useridlist_name,
        isAdd:true,
        disabled:false,
        ids:model[field],
        mode:"multiple",// multiple 多选 single 单选
        onChange: (e: ChangeEvent) => {
          // if(model[field]){
          //   model[field] += ","+e.ids;
          //   model.useridlist_name +=","+e.names;
          // }else{
          //   model[field] = e.ids;
          //   model.useridlist_name=e.names;
          // }
         // console.log("---e.names",e.names)
          model[field] = e.ids;
          model.useridlist_name=e.names;
        },
      });
    },
  },
  {
    label: '新增成员-名称',
    field: 'addUserIds_name',
  },
  {
    label: '新增成员',
    field: 'addUserIds',
    component: 'Input',
    render: ({ model, field }) => {
      return h(Ainput, {
        placeholder: '请选择人员',
        value: model.addUserIds_name,
        isAdd:false,
        ids:model[field],
        mode:"multiple",// multiple 多选 single 单选
        onChange: (e: ChangeEvent) => {
          model[field] = e.ids;
          model.addUserIds_name=e.names;
        },
      });
    },
  },
  {
    field: 'startDate',
    label: '统计开始日期',
    required: true,
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    }
  },
  {
    field: 'totalType',
    label: '统计方式',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '从起始日期开始统计', value: 1 },
        { label: '按当前月份统计', value: 2 },
        { label: '按当年统计', value: 3 },

      ],
    },
  },
  {
    field: 'templatePrefix',
    label: '消息模版前缀',
    component: 'InputTextArea',
    componentProps: {
      rows:4
    }
  },
  {
    field: 'templateSuffix',
    label: '消息模版后缀',
    component: 'InputTextArea',
    componentProps: {
      rows:4
    }
  },
  {
    field: 'nameSuffix',
    label: '消息 姓名后缀',
    component: 'Input',
  },
  // {
  //   label: '群主',
  //   field: 'owner',
  //   component: 'ApiTreeSelect',
  //   componentProps: {
  //     api: getLevelSelectsApi,
  //     resultField:"data",
  //     labelField: 'label',
  //     valueField: 'value',
  //   },
  //   required: true,
  // }

];
